<template>
  <el-dialog class="dia-style" :title="title" :visible.sync="isOpen" width="60%" append-to-body>
    <el-form ref="form" :model="formData" :rules="rules" label-width="100px">
      <el-form-item label="产品名称" prop="name">
        <el-input v-model="formData.name" placeholder="请输入名称"/>
      </el-form-item>
      <el-form-item label="产品类型" prop="roleKey">
        <div class="form-item-wk">
          <div :class="['form-item',currentIndex==i?'active':'']" v-for="(item,i) in options" :key="i" @click="handleClick(i)">
            <img :src="require('@/assets/images/import/'+item.img+'.png')" alt="">
            <p>{{ item.name }}</p>
          </div>
          <span></span>
          <span></span>
          <span></span>
          <span></span>
        </div>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
//  模拟数据
import importData from '../../views/accessProduct/mockData/importData.json'

export default {
  name: 'editProduct',
  props: {
    title: {
      type: String,
      default() {
        return '编辑'
      }
    },
    formData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      currentIndex:null,
      isOpen: false,
      options: importData,
      // 表单参数
      rules: {
        roleName: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        roleKey: [
          { required: true, message: '产品类型不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {},
  methods: {
    handleClick(i){
      this.currentIndex=i
    },
    /** 提交按钮 */
    submitForm: function() {
      this.isOpen=false;
      /*      this.$refs['form'].validate(valid => {
              if (valid) {
                if (this.formData.roleId != undefined) {
                  this.$modal.msgSuccess('修改成功')
                  this.isOpen = false
                  this.$emit('changeOpen', false)
                } else {
                  this.$modal.msgSuccess('新增成功')
                  this.isOpen = false
                  this.$emit('changeOpen', false)
                }
              }
            })*/
    },
    // 取消按钮
    cancel() {
      this.isOpen = false
      this.formData={}
      this.$emit('changeOpen', false)
    }
    //
  }
}
</script>

<style lang="scss" scoped>
.el-cascader {
  width: 100%;
}

.form-item-wk {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  //align-items: stretch;
  text-align: center;

  span {
    width: 15%;
  }

  .form-item {
    margin-bottom: 20px;
    cursor: pointer;
    width: 15%;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: 4px;
    &.active{
      border:1px solid #4B6EEF;
    }
    &:hover{
      border:1px solid #4B6EEF;
    }
    img {
      display: block;
      margin: 20px auto;
    }

    p {
      height:50px;
      display:flex;
      justify-content: center;
      align-items: center;
      padding:0px 10px;
      line-height: 20px;
      vertical-align: center;
      margin: 0;
      border-top: 1px solid rgba(0, 0, 0, .15);
    }
  }
}
::v-deep .el-dialog__body{
  height:70vh;
  overflow: auto;
}
</style>
